import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import postcssPxToViewport from "postcss-px-to-viewport";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    proxy: {
      // 当匹配到api开头的
      // https://52coding.cc/yuantiku_api

      // http://127.0.0.1:5193/api 对应 https://52coding.cc/yuantiku_api
      // http://127.0.0.1:5193/api/6666 对应的是 https://52coding.cc/yuantiku_api/6666

      "^/api": {
        target: "https://52coding.cc/yuantiku_api/",
        changeOrigin: true, // 换源
        rewrite(url) {
          return url.replace(/^\/api/, "");
        },
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  css: {
    postcss: {
      plugins: [
        postcssPxToViewport({
          unitToConvert: "px",
          viewportWidth: 375,
          unitPrecision: 5,
          propList: ["*"],
          viewportUnit: "vw",
          fontViewportUnit: "vw",
          selectorBlackList: [],
          minPixelValue: 1,
          mediaQuery: false,
          replace: true,
          exclude: undefined,
          include: undefined,
          landscape: false,
          landscapeUnit: "vw",
          landscapeWidth: 568,
        }),
      ],
    },
  },
});
